package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.daomu.config.DaoMuActivityConfig;
import com.yanqu.road.entity.activity.daomu.config.DaoMuCrowbarBoxConfig;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGoodsType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.TempCommonMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.daomu.DaoMuActivityMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DaoMuRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        Map<Integer, DaoMuActivityConfig> activityConfigMap = DaoMuActivityMgr.getActivityConfigMap();
        for (DaoMuActivityConfig daoMuActivityConfig : activityConfigMap.values()) {
            ActivityInfo activityInfo = daoMuActivityConfig.getActivityInfo();
            if (activityInfo.getType() != eActivityType.DaoMu.getValue()) {
                continue;
            }
            //回收时间-领奖期后回收
            long recycleTime = activityInfo.getEndShowTime() * 1000 + 600 * 1000;
            //积分道具ID
            int scoreItemId = daoMuActivityConfig.getScorePropId();
            //需要回收的道具-宝箱兑换成积分
            for (DaoMuCrowbarBoxConfig daoMuCrowbarBoxConfig : daoMuActivityConfig.getCrowbarBoxConfigMap().values()) {
                ArrayList<String> stringList = new ArrayList<>();
                String[] costArr = daoMuCrowbarBoxConfig.getCost().split("=");
                //回收的道具ID
                int recyclePropId = Integer.parseInt(costArr[0]);
                stringList.add(String.valueOf(recyclePropId));
                stringList.add(String.valueOf(scoreItemId));
                stringList.add("0");
                stringList.add(activityInfo.getActivityName());
                ActivityItemRecycleMgr.addRecycleItemData(recyclePropId, activityType, 1, recycleTime, stringList);
            }
            //角色道具回收时间-活动展示期结束回收
            long recycleRoleTime = activityInfo.getEndShowTime() * 1000 + 600 * 1000;
            //需要回收的道具-角色人偶-直接清空
            int roleGoodsType = daoMuActivityConfig.getRoleGoodsType();
            Map<Integer, GoodsInfo> goodsInfoMap = GoodsMgr.getGoodsMapByType(roleGoodsType);
            for (GoodsInfo goodsInfo : goodsInfoMap.values()) {
                ActivityItemRecycleMgr.addRecycleItemData(goodsInfo.getGoodsId(), activityType, 2, recycleRoleTime,  new ArrayList<>());
            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.DaoMu.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1) {
            item2Score(userId, data);
        } else if (data.getRecycleType() == 2) {
            UserBagItem userBagItem = getUserBagItem(userId, data.getItemId());
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
